//
//  DSZMeViewController.m
//  7.13苏宁框架
//
//  Created by app01 on 15/7/21.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZMeViewController.h"
#import "DSZMainViewController.h"
#import "Common.h"
#import "NewMeView.h"

@interface DSZMeViewController ()<MyShowClickBtnDelegate>

//发布的内容的图片
@property(strong,nonatomic)UIImageView *contentImage;
@property(strong,nonatomic)UIView *contentView;

@property(strong,nonatomic)NewMeView *myView;
@property(strong,nonatomic)UIImageView *bgImgae;
@property(strong,nonatomic)UILabel *messageaLabel;
@property(strong,nonatomic)UITextField *textField;

@end

@implementation DSZMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _myView = [[NewMeView alloc]init];
    _myView.delegate = self;
    _myView.top = 20+44;
    [self.view addSubview:_myView];
    _bgImgae = _myView.selectBG;
    _messageaLabel = _myView.messageLabel;
    _contentView = _myView.contentView;
    
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addImage:) name:@"postTopic" object:nil];

}



-(void)addImage:(NSNotification *)notification{
    UIImageView *image = notification.object;
    _contentImage = image;
    //NSLog(@"========%@",NSStringFromCGRect(_contentImage.frame));
}


//返回首页
- (IBAction)returnMain:(UIBarButtonItem *)sender {
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    DSZMainViewController *vc=[story instantiateViewControllerWithIdentifier:@"main"];
    [self presentViewController:vc animated:NO completion:nil];
}


#pragma mark MyShowClickBtnDelegate方法

-(void)clickAction:(UIButton *)btn{
    _myView.selectedBtn.selected = NO;
    btn.selected = !btn.selected;
    _myView.selectedBtn = btn;
    _bgImgae.left = btn.left;
    if (btn.tag == 20) {
        
        UIImageView *noImage = (UIImageView *)[_contentView viewWithTag:5];
        noImage.hidden = NO;
        _messageaLabel.hidden = NO;
        UIImageView *image = (UIImageView *)[_contentView viewWithTag:6];
        image.hidden = YES;
        
        _contentView.transform = CGAffineTransformMakeTranslation(_contentView.frame.size.width, 0);
        _contentView.alpha = 0;

        [UIView animateWithDuration:0.5 animations:^{
        
            _contentView.transform = CGAffineTransformIdentity;
            _contentView.alpha = 1;
           _messageaLabel.text = @"没有Show，赶快Show出新内容";
            
        }completion:^(BOOL finished) {
            // 恢复属性
            _contentView.transform = CGAffineTransformIdentity;
            _contentView.alpha  = 1;

        }];

        
    }else{
    
        if (_contentImage != nil) {
            
            UIImageView *noImage = (UIImageView *)[_contentView viewWithTag:5];
            noImage.hidden = YES;
            _messageaLabel.hidden = YES;
            _contentImage.hidden = NO;
            
            UIImageView *image = [[UIImageView alloc]init];
            image.frame = CGRectMake(10, 10, 100, 100);
            image.image = _contentImage.image;
            image.tag = 6;
            image.backgroundColor = [UIColor redColor];
            //NSLog(@"jgffd%@",NSStringFromCGRect(image.frame));
            [_contentView addSubview:image];
            
    
        }else{
            
            _contentView.transform = CGAffineTransformMakeTranslation(-_contentView.frame.size.width, 0);
            _contentView.alpha = 0;
            
            [UIView animateWithDuration:0.5 animations:^{
                
                _contentView.transform = CGAffineTransformIdentity;
                _contentView.alpha = 1;
                _messageaLabel.text = @"没有参与话题，赶快行动起来";
                
                
            }completion:^(BOOL finished) {
                // 恢复属性
                _contentView.transform = CGAffineTransformIdentity;
                _contentView.alpha  = 1;
                
            }];

        }
       

    }
}

-(void)clickTextFiled:(UITextField *)textFiled{
    [textFiled resignFirstResponder];
}


-(void)saveSign:(UITextField *)textFiled{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setValue:textFiled.text forKey:@"sign"];
    
}


-(void)dealloc{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
